#ifndef _DBIMPL_HXX_
#define _DBIMPL_HXX_

#include "indexedlist.hxx"
#ifdef WIN32
#include <winsock2.h>
#endif

#if defined(linux)
#include "mysql/mysql.h"
#elif defined(WIN32)
#include "mysql.h"
#endif

#include "mydb.hxx"

class FileLog;
class DBImpl
{
public:
  DBImpl(const string &server_address,
	 const string &login, 
	 const string &password, 
	 const string &database, 
	 tUInt16 port, FileLog *filelog=0);
  virtual ~DBImpl();
  tBool Connect();
  tBool Disconnect();
  const char *LastErrorMsg();
  tUInt32 ErrNo() const ;
  tSInt32 LastErrorCode();
  DB::tQueryId Query(const string &query);
  char **FetchQuery(DB::tQueryId qid);
  tUInt32 NumFieldsQuery(DB::tQueryId qid);
  bool FreeQuery(DB::tQueryId qid);
  void Ping();
  tUInt32 LastInsertId();
  tUInt32 AffectedRows();
    
private:
  MYSQL *_conn;
  IndexedList<MYSQL_RES *> _result_list;
  string _server_address;
  string _login; 
  string _password;
  string _database; 
  tUInt16 _port;
  FileLog *_filelog;
  static tUInt32 _lib_usage_counter;
};


#endif // _DBIMPL_HXX_

